package com.dcbeida.activity.features;


import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.util.Log;

import com.dcbeida.bean.User;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.model.FeaturesModel;

import java.lang.reflect.Type;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by hp on 2016/5/12.
 */
public class FeaturesPresenter implements FeaturesContract.Present {


    private FeaturesContract.View view;

    private FeaturesModel model;

    private Activity act;

    public FeaturesPresenter(FeaturesContract.View view, Activity act) {
        //我这里直接把activity作为view，所以不需要
        //mView.setPresenter(this);
        this.view = view;
        model = FeaturesModel.newInstance();
        this.act=act;

    }

    @Override
    public void bindDevicetoken(String devicetoken) {
        model.bindDevicetoken(devicetoken,new bindCallBack(act,User.class,lis));
    }

    @Override
    public void start() {

    }



    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model.getCancel();
        }
    };


    final class bindCallBack<T> extends DialogCallback<T> {

        public bindCallBack(Activity activity, Type type, DialogInterface.OnCancelListener listener) {
            super(activity, type, listener);
        }

        @Override
        public void onResponse(T data) {
            if(data!=null) {
                //绑定成功失败返回
            }

        }


        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            //view.showTip("网络异常，请重试");
            Log.i("sean","+++++++绑定Umeng账号失败");
        }
    }



}
